package gdonly.top.signin.business;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;

import gdonly.top.signin.R;
import gdonly.top.signin.utils.DatabaseQuery;

/**
 * Created by zhuzhuxia on 2017/5/14.
 */
public class QueryByCourseActivity extends AppCompatActivity {
    private Spinner spinner;
    private Button queryBtn;
    private String courseId, courseName;
    private String[] courseIds = {"001","002", "003", "004", "005"};
    private String[] courseNames;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_querybycourse);
        initViews();

    }
    private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.querybycourse_start:

                    String classId = ((Application)getApplication()).getThisUser().getClassId();
                    String result = DatabaseQuery.getCourseSignInfo(classId, courseId, QueryByCourseActivity.this);
                    Intent intent = new Intent(QueryByCourseActivity.this, QueryRecordsByCourseActivity.class);
                    intent.putExtra("result", result);
                    intent.putExtra("course_name",courseName);
                    intent.putExtra("course_id",courseId);
                    Log.e("TAG","courseid:"+courseId);
                    startActivity(intent);

                    break;
            }
        }
    };


    private void initViews(){
        courseNames = getResources().getStringArray(R.array.courses);
        spinner = (Spinner) findViewById(R.id.spinner2);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                courseId = courseIds[position];
                courseName = courseNames[position];
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                courseId = courseIds[0];
                courseName = courseNames[0];
            }

        });
        queryBtn = (Button) findViewById(R.id.querybycourse_start);
        queryBtn.setOnClickListener(listener);



    }
}
